** This do file aggregatres the mission data into grid-country observations

** Nunn data
import excel "Grid Africa\Files\roome_grid.xlsx", sheet("nunn_country_grid") firstrow case(lower) clear

collapse (sum)  catholics protest bfbs, by(grid_country gridcell)

rename protestant protest_nunn
label var protest_nunn "N Protestant Missions (Roome 1924), coord adj"

rename catholic catholic_nunn
label var catholic "N Catholic Missions (Roome 1924), coord adj"

rename bfbs bfbs_nunn
label var bfbs_nunn "N BFBS (Roome 1924), coord adj"

tempfile nunn
save "`nunn'"


** CR data
import excel "Grid Africa\Files\cr_grid.xlsx", sheet("cr_country_grid") firstrow case(lower) clear
gen protestant_cr_original=1

collapse (sum)  print1903 protestant_cr_original, by(grid_country gridcell)

rename print1903 print1903_original
label var print1903_original "Printing Press (CR)"
label var protestant_cr_original "N Protestant missions (CR)"

* Merge CR & Nunn data
merge 1:1 grid_country gridcell using `nunn', nogenerate

rename grid_country country
replace country="Equatorial Guinea" if country=="Eq. Guinea" // Standardize country names
drop if gridcell=="WG421" & country=="Malawi" // CR coded a mission station in the middle of Lake Malawi
drop if gridcell=="" // Drops the mission stations in NORTH AFRICA


* Merge with grid_country so to fill missing values in country
** Note country, region and district in grid_country.dta was manually checked and assigned the location of the mission
merge 1:1 gridcell country using "Grid Africa\Files\grid_country.dta", nogenerate //grid_country
label var country "Country of mission, OR centroid"

* Merge with gridcell2 - getting the full data set of gridcells
merge m:1 gridcell using "Grid Africa\Files\grid_gridcell2.dta", nogenerate // There is only 1 gridcell which has 2 mission stations in 2 different countries

order gridcell gridcell2, before(country)

foreach x of varlist print1903_original protestant_cr_original catholic_nunn protest_nunn bfbs_nunn {
replace `x'=0 if `x'==.
}
label var gridcell "Gridcell ID 0.1 x 0.1"

save "Grid Africa\Files\grid_missions.dta", replace
